﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L.Basic.Authority.Models;

namespace L.Basic.Authority.Context
{
    /// <summary>
    /// 用户认证上下文
    /// </summary>
    public class Context
    {
        public User CurrentUser { get; set; }
        public IList<ModulePermission> Permissions { get; set; }

        public bool IsInRole(string role)
        {
            return CurrentUser.Roles.Count(c => c.Code.Equals(role,StringComparison.CurrentCultureIgnoreCase)) == 1;
        }

        public bool HasPermission(string moduleName, string permission)
        {
            return Permissions.Count(c => c.Module.Id == moduleName && c.Permission.Id == permission) == 1;
        }
    }
}
